package com.gitee.xmhzzz.component.rocketmq.context;

import com.alibaba.ttl.TransmittableThreadLocal;

/**
 * @ClassName TraceContext
 * @Description
 * @Author wzq
 * @Date 2023/12/5 9:43
 * @Version 1.0
 */
public class TraceContext {
    private static final TransmittableThreadLocal<String> TRACE_ID = new TransmittableThreadLocal<>();

    private static final TransmittableThreadLocal<String> SPAN_ID = new TransmittableThreadLocal<>();

    public static String getTraceId() {
        return TRACE_ID.get();
    }

    public static void setTraceId(String traceId) {
        TRACE_ID.set(traceId);
    }

    public static String getSpanId() {
        return SPAN_ID.get();
    }

    public static void setSpanId(String spanId) {
        SPAN_ID.set(spanId);
    }

    public static void clear() {
        TRACE_ID.remove();
        SPAN_ID.remove();
    }

}
